DXL "formal" programming structure

Hey All,

Another dumb question.
What is the so called "formal" structure of DXL?
Is there any? Does it just do top down?
It is so hard to read code when it is not in a given structure and things are just
splashed all over the palce will nilly.
So, when I start writing in DXL, instead of just tweaking and such, or when I start revamping
some of my inherited DXL scripts, then I want to confirm to the majority of how people think it should look. And where I am there is basically just me, so I don't have to worry about here.

How do you guys like to structure your programs/scripts?
advice? tips? comments?
thanks!
Jerry
SystemAdmin - Thu Jul 28 13:25:33 EDT 2011

Re: DXL "formal" programming structure
kbmurphy - Thu Jul 28 21:31:09 EDT 2011

It's top down.

Advice: Figure out what your globals are going to be and compartmentalize each routine...make sure each routine does a specific thing.

I personally like using function names that make sense with the action....something like:

int getNumberOfShallsInModule(Module mGiven) {
//insert code here
}

Skip retrieveObjectsCreatedEarlierThan(Date dtGiven){
}

Another thing--try to name variables after what they represent...as in

string strMyModule = "/Path/To/My/Module"
Skip skObjs = create
int iToReturn
Object oSource
Link lCurrent

etc.

Again, sorry for not using official syntax for code examples. When this forum supports Chrome and Safari, my posts will look much better. ;)

Have fun!

Re: DXL "formal" programming structure
llandale - Sun Jul 31 23:48:16 EDT 2011

You understand that functions execute top down, but they reference functions that are defined above. The first functions to execute are at the bottom of the script. Often, the final statement in the file is the first one that actually executes, not counting global declarations and initializations.

Many DXL scripts involve dialog boxes. Usually functions in callbacks (when the user pushes a button) refer to the elements on the dialog, such as reading the name of the entered file. So usually, the element variables must be declared globally; and for me I just always declare the dialog and its elements globally, not worrying about which ones really need to be.

You can of course have nested blocks of braces { {} {} }. You CAN have nested functions, but sadly the inside functions cannot reference variables in the housing function. You cannot do this:
void Master()

{  int i = 0
   void Slave()
   {  i++
   }
   Slave()
}


Thus, using nested functions seems to just add a level of confusion and I avoid it.

There are times that you must declare certainly arrays globally at the exact correct size; such as when using to populate certain Elements. That's a drag. You first declare the size of the array as an int variable, call some functions to determine the size (e.g. the number of Enumerations), then declare that array, then populate the array; all this during "initialization". But lets forget that.

So, here's my basic structure:
{code}
// NameScript.dxl - phrase what it does
/* NameScript.dxl
paragraphs what it does with a view toward explaining
why the user would want to run the script
.. boring standard block of script characteristics
*/
pragma runLim, 0
#include my massive library, 1000+ useful functions
Globally defined variables
Globally defined DB and DBE Boxes and Elements
Globally defined "help" text; and applyHelp function to display it

Initialize function
Terminate function

Generic functions local to this script
Callback functions invoked from the dialog
.. Occationally I'll slip in global variables that have a particular use by particular functions following.
.. If the variable is needed to understand the script then it always goes at the top.
other callbacks
Main BuildDialog function

// **** MAIN CODE ****
invoke that BuildDialog Function
//end of NameScript.dxl

 

 

  • Louie

Folks with sharper memories and can juggle 20 balls don't need such rigor, but then they end up writing code nobody else can figure out; often including themselves later on down the road.

 

 

Re: DXL "formal" programming structure
SystemAdmin - Mon Aug 01 13:31:04 EDT 2011

llandale - Sun Jul 31 23:48:16 EDT 2011

You understand that functions execute top down, but they reference functions that are defined above. The first functions to execute are at the bottom of the script. Often, the final statement in the file is the first one that actually executes, not counting global declarations and initializations.

Many DXL scripts involve dialog boxes. Usually functions in callbacks (when the user pushes a button) refer to the elements on the dialog, such as reading the name of the entered file. So usually, the element variables must be declared globally; and for me I just always declare the dialog and its elements globally, not worrying about which ones really need to be.

You can of course have nested blocks of braces { {} {} }. You CAN have nested functions, but sadly the inside functions cannot reference variables in the housing function. You cannot do this:
void Master()

{  int i = 0
   void Slave()
   {  i++
   }
   Slave()
}


Thus, using nested functions seems to just add a level of confusion and I avoid it.

There are times that you must declare certainly arrays globally at the exact correct size; such as when using to populate certain Elements. That's a drag. You first declare the size of the array as an int variable, call some functions to determine the size (e.g. the number of Enumerations), then declare that array, then populate the array; all this during "initialization". But lets forget that.

So, here's my basic structure:
{code}
// NameScript.dxl - phrase what it does
/* NameScript.dxl
paragraphs what it does with a view toward explaining
why the user would want to run the script
.. boring standard block of script characteristics
*/
pragma runLim, 0
#include my massive library, 1000+ useful functions
Globally defined variables
Globally defined DB and DBE Boxes and Elements
Globally defined "help" text; and applyHelp function to display it

Initialize function
Terminate function

Generic functions local to this script
Callback functions invoked from the dialog
.. Occationally I'll slip in global variables that have a particular use by particular functions following.
.. If the variable is needed to understand the script then it always goes at the top.
other callbacks
Main BuildDialog function

// **** MAIN CODE ****
invoke that BuildDialog Function
//end of NameScript.dxl

 

 

  • Louie

Folks with sharper memories and can juggle 20 balls don't need such rigor, but then they end up writing code nobody else can figure out; often including themselves later on down the road.

 

 

Hi Louie,
Thanks for the response!
I kind of figured it was top down liek you mentioned, juse I have seen from some programs.
It has been a while since I used that method, but I can do it.
My predecessors seemed to have a hard time with that.
They also like to do multiple nesting, or one fucntion/procedure calling another, and then that walling calling, etc.
I try to avoid that as much as possible.
I liek your very last statement! How true it is.
Thank goodness I only encounter that in certain areas, and not the whole program!

Thanks!
Jerry